﻿using AutoMapper;
using BasicData.API.Read.Applications.Commands;
using BasicData.API.Read.Dtos;
using BasicData.Domain;
using BasicData.ErrorCode;
using BasicData.Infrastrueturc.Interfaces;
using MediatR;

namespace BasicData.API.Read.Applications.CommandHandlers
{
    public class AppDetailQueryCommandHandler : IRequestHandler<AppDetailQueryCommand, APIResult<RoomDTO>>
    {
        private readonly IBaseReposiotry<Room> roomReposiotry;
        private readonly IMapper mapper;
        public AppDetailQueryCommandHandler(IBaseReposiotry<Room> roomReposiotry, IMapper mapper)
        {
            this.roomReposiotry = roomReposiotry;
            this.mapper = mapper;
        }

        public Task<APIResult<RoomDTO>> Handle(AppDetailQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<RoomDTO> result=new APIResult<RoomDTO> ();
            result.Code=ResultCode.查询成功;
            result.Message=ResultCode.查询成功.ToString();

            var list=roomReposiotry.GetAll().FirstOrDefault(c=>c.RoomId==request.InforId);
             result.Data=mapper.Map<RoomDTO>(list);
            return Task.FromResult (result);
        }
    }
}
